package com.a3dweijing.wetouch2.adapter;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.bean.BusinessDemand;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by yxd on 2017/11/17.
 */

public class BusinessAdapter extends RecyclerView.Adapter<BusinessAdapter.MyViewHolder> {
    private List<BusinessDemand> demands;
    private SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm");
    public BusinessAdapter(List<BusinessDemand> demands) {
        this.demands = demands;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_business,parent,false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        String telephone=demands.get(position).getUser_telnum();
        if (telephone!=null && telephone.length()==11){
            telephone=telephone.substring(0,3)+"****"+telephone.substring(7);
        }else {
            telephone="";
        }
        holder.name.setText(demands.get(position).getUser_name()+"  "+telephone);
        holder.time.setText(format.format(new Date(demands.get(position).getThree_d_demand_time())));
        holder.content.setText(demands.get(position).getThree_d_demand_contend());
        if (demands.get(position).getThree_d_demand_state()==1){
            holder.status.setText("审核中。。。");
        }
    }

    @Override
    public int getItemCount() {
        return demands.size();
    }

    class MyViewHolder extends ViewHolder {
        TextView name,time,content,status;
        public MyViewHolder(View itemView) {
            super(itemView);
            name= (TextView) itemView.findViewById(R.id.business_name);
            time= (TextView) itemView.findViewById(R.id.business_time);
            content= (TextView) itemView.findViewById(R.id.business_content);
            status= (TextView) itemView.findViewById(R.id.business_status);
        }
    }
}
